﻿using System;
using System.Collections.Generic;
using MigSharp;

namespace CmsDatabaseMigrations.Migrations
{    
    public abstract class BatchMigration : StoredProcedureMigration
    {
        private string internalSpName;
        protected override string SpFileName { get { return internalSpName; }}

        protected abstract IEnumerable<string> SpFileNames { get; }
        protected abstract IEnumerable<Action<IDatabase>> UpActions { get; }
        protected abstract IEnumerable<Action<IDatabase>> DownActions { get; }

        public override void Up(IDatabase db)
        {
            foreach (var upAction in UpActions)
            {
                upAction(db);
            }

            foreach (var spFileName in SpFileNames)
            {
                internalSpName = spFileName;
                base.Up(db);
            }
        }

        public override void Down(IDatabase db)
        {
            foreach (var action in DownActions)
            {
                action(db);
            }

            foreach (var spFileName in SpFileNames)
            {
                internalSpName = spFileName;
                base.Down(db);
            }
        }
    }
}